/*
 * @lc app=leetcode.cn id=71 lang=javascript
 *
 * [71] 简化路径
 */

// @lc code=start
/**
 * @param {string} path
 * @return {string}
 */
var simplifyPath = function (path) {
  let stack = [];
  path
    .replace(/\/+/g, '/')
    .split('/')
    .forEach(item => {
      switch (item) {
        case '.':
        case '':
          break;
        case '..':
          stack.pop();
          break;
        default:
          stack.push(item);
      }
    })
  return `/${stack.join('/')}`;
};
// @lc code=end
